﻿using System.Windows;
using System.Windows.Controls;
using Schuifpuzzel.Model;
using Schuifpuzzel.MyKinect;

namespace Schuifpuzzel
{
    /// <summary>
    /// Interaction logic for TrackingScreen.xaml
    /// </summary>
    public partial class TrackingScreen : UserControl
    {
        public TrackingScreen()
        {
            InitializeComponent();

        }

        /// <summary>
        /// Resize the trackingscreen components so they fit on the puzzlescreen.
        /// </summary>
        /// <param name="canvasSize">width of the space available next to the puzzle.</param>
        public void SetSize(double canvasSize)
        {
            double safeZoneSize = canvasSize / 3 * 2;
            mainCanvas.Height = canvasSize;
            mainCanvas.Width = canvasSize;

            line1.X2 = canvasSize;
            line1.Y2 = canvasSize;
            line2.X1 = canvasSize;
            line2.Y2 = canvasSize;
            Up.Height = canvasSize / 10;
            Down.Height = canvasSize / 10;
            Left.Height = canvasSize / 10;
            Right.Height = canvasSize / 10;
            Up.Width = canvasSize / 10;
            Down.Width = canvasSize / 10;
            Left.Width = canvasSize / 10;
            Right.Width = canvasSize / 10;
            UpWhite.Height = canvasSize / 10;
            DownWhite.Height = canvasSize / 10;
            LeftWhite.Height = canvasSize / 10;
            RightWhite.Height = canvasSize / 10;
            UpWhite.Width = canvasSize / 10;
            DownWhite.Width = canvasSize / 10;
            LeftWhite.Width = canvasSize / 10;
            RightWhite.Width = canvasSize / 10;
            Canvas.SetLeft(Up, (canvasSize / 2) - Up.Width / 2);
            Canvas.SetLeft(Down, (canvasSize / 2) - Down.Width / 2);
            Canvas.SetTop(Left, (canvasSize / 2) - Left.Height / 2);
            Canvas.SetTop(Right, (canvasSize / 2) - Right.Height / 2);
            Canvas.SetTop(Up, (canvasSize - safeZoneSize) / 4 - Down.Width / 2);
            Canvas.SetBottom(Down, (canvasSize - safeZoneSize) / 4 - Down.Width / 2);
            Canvas.SetLeft(Left, (canvasSize - safeZoneSize) / 4 - Right.Height / 2);
            Canvas.SetRight(Right, (canvasSize - safeZoneSize) / 4 - Right.Height / 2);
            Canvas.SetLeft(UpWhite, (canvasSize / 2) - UpWhite.Width / 2);
            Canvas.SetLeft(DownWhite, (canvasSize / 2) - DownWhite.Width / 2);
            Canvas.SetTop(LeftWhite, (canvasSize / 2) - LeftWhite.Height / 2);
            Canvas.SetTop(RightWhite, (canvasSize / 2) - RightWhite.Height / 2);
            Canvas.SetTop(UpWhite, (canvasSize - safeZoneSize) / 4 - DownWhite.Width / 2);
            Canvas.SetBottom(DownWhite, (canvasSize - safeZoneSize) / 4 - DownWhite.Width / 2);
            Canvas.SetLeft(LeftWhite, (canvasSize - safeZoneSize) / 4 - RightWhite.Height / 2);
            Canvas.SetRight(RightWhite, (canvasSize - safeZoneSize) / 4 - RightWhite.Height / 2);

            safeZone.Height = safeZoneSize;
            safeZone.Width = safeZoneSize;
            Canvas.SetLeft(safeZone, canvasSize / 6);
            Canvas.SetTop(safeZone, canvasSize / 6);

            double temp = safeZoneSize / GestureDetector.ScaledDistanceToSwipe * GestureDetector.ScaledDistanceToBeInStart;
            startPosition.Height = temp;
            startPosition.Width = temp;
            Canvas.SetLeft(startPosition, (canvasSize - temp) / 2);
            Canvas.SetTop(startPosition, (canvasSize - temp) / 2);

            double handSize = safeZoneSize / 20;

            handPosition.Height = handSize;
            handPosition.Width = handSize;
            Canvas.SetLeft(handPosition, (canvasSize / 2) - handSize / 2);
            Canvas.SetTop(handPosition, (canvasSize / 2) - handSize / 2);

        }

        public void MakeArrowWhite(MoveDirection direction)
        {
            switch (direction)
            {
                case MoveDirection.Down:
                    Down.Visibility = Visibility.Hidden;
                    DownWhite.Visibility = Visibility.Visible;
                    break;
                case MoveDirection.Up:
                    Up.Visibility = Visibility.Hidden;
                    UpWhite.Visibility = Visibility.Visible;
                    break;
                case MoveDirection.Left:
                    Left.Visibility = Visibility.Hidden;
                    LeftWhite.Visibility = Visibility.Visible;
                    break;
                case MoveDirection.Right:
                    Right.Visibility = Visibility.Hidden;
                    RightWhite.Visibility = Visibility.Visible;
                    break;
            }
        }

        public void MakeArrowsWhite()
        {
            Down.Visibility = Visibility.Visible;
            DownWhite.Visibility = Visibility.Hidden;
            Up.Visibility = Visibility.Visible;
            UpWhite.Visibility = Visibility.Hidden;
            Left.Visibility = Visibility.Visible;
            LeftWhite.Visibility = Visibility.Hidden;
            Right.Visibility = Visibility.Visible;
            RightWhite.Visibility = Visibility.Hidden;
        }
    }
}
